<?php

class IsCore {

  function p (&$shop,$params) {
     for ($i=0;$i<count($params);$i++) $str .= $params[$i];
     $shop->out($str);
  }

  function pln (&$shop,$params) {
     for ($i=0;$i<count($params);$i++) $str .= $params[$i];
     $shop->out($str."\n");
  }

  function str (&$shop,$params = '') {
     if ($params){
       for ($i=0;$i<count($params);$i++){
          $str .= ','.$params[$i];
       }
       $str = substr($str,1);
       return $params[0];
     }
  }

  function initrange (&$shop,$params) {
     $this->rangeval[$params[0]] = -1;
  }

  // p1 : rangename; p2 : limit; p3 : stepwidth
  function range (&$shop,$params) {
     if ($params[2]){
       $this->rangeval[$params[0]] += $params[2];
     } else {
       $this->rangeval[$params[0]]++;
     }
     if ($this->rangeval[$params[0]] < $params[1]){
       return true;
     }
  }

  // get value of a rangeval (-counter)
  function yield(&$shop,$params){
    return $this->rangeval[$params[0]];
  }

  function setvar (&$shop,$params) {
     $shop->setVar($params[0],$params[1]);
     if ($params[1]) return true;
  }

  // equal
  function eq (&$shop,$params) {
    if ($params[0] == $params[1]){
       return true;
    }
  }

  // not equal
  function ne (&$shop,$params) {
    if ($params[0] != $params[1]){
       return true;
    }
  }

  // greater than
  function gt (&$shop,$params) {
    if ($params[0] > $params[1]){
       return true;
    }
  }

  // greater than or equal
  function gteq (&$shop,$params) {
    if ($params[0] >= $params[1]){
       return true;
    }
  }

  // less than
  function lt (&$shop,$params) {
    if ($params[0] < $params[1]){
       return true;
    }
  }

  // less than or equal
  function lteq (&$shop,$params) {
    if ($params[0] <= $params[1]){
       return true;
    }
  }

  function cand (&$shop,$params) {
     $state = true;
     for ($i=0;$i<count($params);$i++){
        if (!$params[$i]){
	   return;
	}
     }
     return $state;
  }

  function cor (&$shop,$params) {
     $state = true;
     for ($i=0;$i<count($params);$i++){
        if (!$params[$i]){
	   return;
	}
     }
     return $state;
  }

  function not (&$shop,$params) {
     if ($params[0]){
       return;
     } else {
       return true;
     }
  }

  function sum (&$shop,$params) {
     for ($i=0;$i<count($params);$i++){
        $sum += $params[$i];
     }
     return $sum;
  }

  function prod (&$shop,$params) {
     $prod = 1;
     for ($i=0;$i<count($params);$i++){
        $prod *= $params[$i];
     }
     return $prod;
  }

  function abs (&$shop,$params) {
    if ($params[0] > 0)
      return $params[0];
    else
      return ($params[0] * -1);
  }

  // p1 : amount ; p2 : percentage
  function perCent (&$shop,$params) {
    return ($params[0]/100)*$params[1];
  }

  function getCfgVar(&$shop,$params) {
    $shop->out($shop->{$params[0]}[$params[1]]);
  }

  function includeHttp (&$shop,$params) {
    global $QUERY_STRING;
    if(!preg_match('/^http/',$params[0])) $params[0] = $shop->cfgSF['url'].$params[0];
    $shop->out(join('',file($params[0].'?'.$QUERY_STRING)));
  }

}

?>